package com.hhf.study.controller;


import com.hhf.study.service.ChatAssistant;
import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.output.Response;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
public class ChatLanguageModelController
{
    @Resource
    private ChatLanguageModel chatLanguageModel;
    @Resource
    private ChatAssistant chatAssistant;

    @GetMapping(value = "/chatlanguagemodel/hello")
    public String hello(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt)
    {
        String result = chatLanguageModel.generate(prompt);

        System.out.println("通过langchain4j调用qwen-turbo-0624模型返回结果："+result);

        return result;
    }

    @GetMapping(value = "/chatlanguagemodel/usermessage")
    public String userMessage(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt)
    {
        UserMessage userMessage = UserMessage.from(prompt);

        Response<AiMessage> messageResponse = chatLanguageModel.generate(userMessage);

        System.out.println("通过langchain4j调用qwen-turbo-0624模型返回结果："+messageResponse);

        return messageResponse.toString();
    }

    @GetMapping(value = "/chatlanguagemodel/assistant")
    public String assistant(@RequestParam(value = "prompt", defaultValue = "中国有哪些菜系") String prompt)
    {

        String chat = chatAssistant.chat(prompt);

        System.out.println("通过langchain4j调用qwen-turbo-0624模型返回结果："+chat);

        return chat;
    }
}
